package com.hegaoye.mqhandler;

import com.hegaoye.base.RabbitmqConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by lixin on 2019/6/29.
 */
@Slf4j
@Component
public class OrderSender {

    @Resource
    private AmqpTemplate amqpTemplate;

    /**
     * 发送topic 消息
     *
     * @param message
     */
    public void sendTopic(String message) {
        log.info("OrderSender >> " + message);
        amqpTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_NAME, RabbitmqConfig.ORDER_QUEUE_NAME, message);
        amqpTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_NAME, RabbitmqConfig.ORDER_DISCOUNT_QUEUE_NAME, message);
    }

    /**
     * 发送确认模式
     *
     * @param message
     */
    public void sendToConfirm(String message) {
        for (int i = 0; i < 100; i++) {
            amqpTemplate.convertAndSend(RabbitmqConfig.Test_EXCHANGE_NAME, RabbitmqConfig.Test_QUEUE_NAME, message + i);
        }
    }

}
